<template>
  <div class="category">
    <!-- 头部 搜索和登录 -->
    <div class="header">
      <div class="searckBox">荣耀X10</div>
      <div class="msgBtn"></div>
    </div>
    <div class="categoryContent">
      <div class="categoryLeft">
        <div class="item" v-for="(fitem, index) in categoryData" 
          :key="fitem.id"
          @click="categoryLeftItemClick(fitem.id,index)">
          <span :class="[fitem.id === activeID ? 'current' : '']">{{fitem.name}}</span>
        </div>
      </div>
      <div class="categoryRight">
        <div v-for="fitem in subCategorys" :key="fitem.id">
          <div v-if="fitem.type === 1" class="categoryRightType1">
            <div class="item" v-for="item in fitem.subCategorys" :key="item.id">
              <img :src="'https://res.vmallres.com/pimages' + item.photoPath + item.photoName" />
            </div>
          </div>
          <div v-if="fitem.type === 2" class="categoryRightType2">
            <div class="item" v-for="item in fitem.subCategorys" :key="item.id">
              <img :src="'https://res.vmallres.com/pimages' + item.photoPath + item.photoName" />
            </div>
          </div>
          <div v-if="fitem.type !== 1 && fitem.type !== 2" class="categoryRightType3">
            <div class="title">{{fitem.name}}</div>
            <div class="item">
              <div class="imgItem"  v-for="sitem in fitem.subCategorys" :key="sitem.id">
                <img :src="'https://res.vmallres.com/pimages' + sitem.photoPath + sitem.photoName" />
                <div>{{sitem.name}}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Tarbar :activeIndex=1></Tarbar>
  </div>
</template>

<script>
import Tarbar from '../../common/tarbar'
export default {
  name: 'category',
  components: {
    Tarbar
  },
  data () {
    return {
      categoryData: [],
      activeID: 0,
      subCategorys: [],
    }
  },
  methods: {
    // 请求页面数据  本地json数据模拟的
    async getCategoryData() {
      this.categoryData = await this.$http.get('../../../../static/mock/category.json');
      this.subCategorys = this.categoryData[0].subCategorys.sort(this.sortType);
      this.activeID = this.categoryData[0].id;
    },
    categoryLeftItemClick(id,index){
      this.activeID = id;
      this.subCategorys = this.categoryData[index].subCategorys.sort(this.sortType);
    },
    sortType(a,b){
      return a.type-b.type  
    }
  },
  mounted(){
    this.getCategoryData()
  }
}
</script>

<style scoped lang="scss">
.category{
  .header{
    height: 76px;
    padding: 8px;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    flex-wrap: nowrap;
    div{
      height: 66px;
      line-height: 66px;
    }
    .searckBox{
      width: 540px;
      font-size: 26px;
      color: #b3b3b3;
      text-align: left;
      background-color: rgba(155,155,155,.1);
      border-radius: 33px;
      padding-left: 80px;
      background-image: url(../../../../static/images/search.png);
      background-position: 20px center;
      background-repeat: no-repeat;
      background-size: 32px 32px;
    }
    .msgBtn{
      width: 64px;
      background-image: url(../../../../static/images/icon_message_black.png);
      background-position: center center;
      background-repeat: no-repeat;
      background-size: 48px 48px;
    }
  }
  .categoryContent{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: nowrap;
    .categoryLeft{
      width: 168px;
      padding-left: 32px;
      height: calc(100vh - 200px);
      overflow-y: scroll;
      -webkit-overflow-scrolling: touch;
      &::-webkit-scrollbar{
        display: none; 
      }
      .item{
        height: 36px;
        text-align: left;
        font-size: 27px;
        align-items: center;
        padding: 32px 0;
        span{
          color: #333;
          // display: inline-block;
          display: -webkit-box;
          height: 36px;
          line-height: 36px;
        }
        .current{
          color: #e01d20;
          border-right: solid 4px #e01d20;
        }
      }
    }
    .categoryRight{
      padding-right: 20px;
      padding-left: 30px;
      width: 500px;
      height: calc(100vh - 200px);
      overflow-y: scroll;
      -webkit-overflow-scrolling: touch;
      &::-webkit-scrollbar{
        display: none; 
      }
      .categoryRightType1{
        .item{
          height: 140px;
          margin-top: 20px;
          img{
            width: 500px;
            height: 140px;
          }
        }
      }
      .categoryRightType2{
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-y: scroll;
        margin: 20px 0;
        &::-webkit-scrollbar{
          display: none; 
        }
        .item{
          width: 160px;
          height: 80px;
          margin-right: 20px;
          img{
            width: 160px;
            height: 80px;
          }
        }
      }
      .categoryRightType3{
        .title{
          color: #333;
          font-size: 26px;
          height: 80px;
          line-height: 80px;
        }
        .item{
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          flex-wrap: wrap;
          .imgItem{
            width: 136px;
            text-align: center;
            padding: 20px 0;
            margin-right: 30px;
            img {
              width: 100px;
              height: 100px;
            }
            div{
              color: #666666;
              opacity: 0.8;
              width: 120px;
              margin-left: 8px;
              text-align: center;
              word-break: break-all;
              font-size: 22px;
              overflow: hidden;
              -o-text-overflow: ellipsis;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
          }
        }
      }
    }
  }
}
</style>
